package com.ruoyi.students.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.students.domain.registration;
import com.ruoyi.students.service.IregistrationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 登记信息Controller
 * 
 * @author sm
 * @date 2021-05-13
 */
@Controller
@RequestMapping("/students/registration")
public class registrationController extends BaseController
{
    private String prefix = "students/registration";

    @Autowired
    private IregistrationService registrationService;

    @RequiresPermissions("students:registration:view")
    @GetMapping()
    public String registration()
    {
        return prefix + "/registration";
    }

    /**
     * 查询登记信息列表
     */
    @RequiresPermissions("students:registration:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(registration registration)
    {
        startPage();
        List<registration> list = registrationService.selectregistrationList(registration);
        return getDataTable(list);
    }

    /**
     * 导出登记信息列表
     */
    @RequiresPermissions("students:registration:export")
    @Log(title = "登记信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(registration registration)
    {
        List<registration> list = registrationService.selectregistrationList(registration);
        ExcelUtil<registration> util = new ExcelUtil<registration>(registration.class);
        return util.exportExcel(list, "登记信息数据");
    }

    /**
     * 新增登记信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存登记信息
     */
    @RequiresPermissions("students:registration:add")
    @Log(title = "登记信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(registration registration)
    {
        return toAjax(registrationService.insertregistration(registration));
    }

    /**
     * 修改登记信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        registration registration = registrationService.selectregistrationById(id);
        mmap.put("registration", registration);
        return prefix + "/edit";
    }

    /**
     * 修改保存登记信息
     */
    @RequiresPermissions("students:registration:edit")
    @Log(title = "登记信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(registration registration)
    {
        return toAjax(registrationService.updateregistration(registration));
    }

    /**
     * 删除登记信息
     */
    @RequiresPermissions("students:registration:remove")
    @Log(title = "登记信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(registrationService.deleteregistrationByIds(ids));
    }
}
